﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiFirst.IService;
using WebApiFirst.Model.Req;
using WebApiFirst.Model.Res;

namespace WebApiFirst.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class StudentController : ControllerBase
    {
        private readonly IStudentService studentService;

        public StudentController(IStudentService studentService) { 
            this.studentService = studentService;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<List<StudentRes>> GetList()
        {
            return await this.studentService.GetList();
        }

        /// <summary>
        /// 客户端评估
        /// </summary>
        /// <returns></returns>
        [HttpGet("list/ClientApprove")]
        public async Task<IEnumerable<StudentRes>> GetListClientApprove()
        {
            return await this.studentService.GetListClientApprove();
        }

        /// <summary>
        /// 服务端评估
        /// </summary>
        /// <returns></returns>
        [HttpGet("list/ServerApprove")]
        public async Task<IEnumerable<StudentRes>> GetListServerApprove()
        {
            return await this.studentService.GetListServerApprove();
        }

     

        /// <summary>
        /// 获取学生
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("detail/{id}")]
        public async Task<StudentRes?> GetStudent(int id)
        {
            return await studentService.GetStudent(id);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="addReq"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> Add(AddReq addReq)
        {
            return await studentService.Add(addReq);
        }

        /// <summary>
        /// 循环遍历
        /// </summary>
        /// <returns></returns>
        [HttpGet("/ForeachStudents")]
        public async Task ForeachStudents()
        {
            await studentService.ForeachStudents();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="updateReq"></param>
        /// <returns></returns>
        [HttpPut("{id}")]
        public async Task<bool> UpdateStudent(int id,UpdateReq updateReq)
        {
            return await studentService.Update(id,updateReq);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> Delete(int id) 
        {
            return await studentService.Delete(id);
        }

        [HttpGet("middleWare")]
        public async Task<bool> MiddleWareTest()
        {
            return await Task.FromResult(true);
        }

    }
}
